//
//  ViewController2.swift
//  MD5
//
//  Created by 郑东喜 on 2016/11/23.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class ViewController2: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        view.backgroundColor = UIColor.white
        /**
         对象存储 归档操作后写入文件
         
         - parameter key:   键
         - parameter value: 值
         - parameter path: 路径
         - parameter completeHandler: 完成后回调
         */
        let arr = ["1","2","3","4","5","6"]
        
        var line = UIView()
        var btn = UIButton()
        
        for i in 0..<arr.count {

            print(i)
            
            let tf = UITextField(frame: CGRect(x: 45, y: 50 * i, width: Int(UIScreen.main.bounds.width), height: 50))
            tf.tag = 100 + i
            

            tf.placeholder = arr[i]
        
            let img = UIImageView(frame: CGRect(x: 5.0, y: Double(50 * i + 10), width: 30.0, height: 30.0))
            
            img.backgroundColor = UIColor.red
            img.tag = 200 + i
            
            if i == 1 || i == 2 || i == 3 || i == 4 || i == 5 {
                line = UIView(frame: CGRect(x: 0, y: 50 * i, width: Int(UIScreen.main.bounds.width), height: 1))
                
                line.backgroundColor = UIColor.red
            }
            
            
//            let btn = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 80 - 30, y: Double(50 * i + 10), width: 80, height: 30))
            let btn = UIButton()
            btn.frame = CGRect(x: Int(UIScreen.main.bounds.width - 80 - 30), y:50 * i + 10, width: 80, height: 30)
            if i == 2 {
                btn.backgroundColor = UIColor.black
                btn.tag = 300

//                btn.addTarget(self, action: #selector(ViewController2.touchI), for: .touchUpInside)
            }
            
            tf.backgroundColor = UIColor.gray
            view.addSubview(tf)
            view.addSubview(img)
            view.addSubview(line)
            view.addSubview(btn)
        }
        
        let btnTag = view.viewWithTag(300) as! UIButton
        btnTag.addTarget(self, action: #selector(ViewController2.touchI), for: .touchUpInside)
    }
    
    func touchI() -> Void {
        print("按钮单机事件")
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let tfText = view.viewWithTag(102) as! UITextField
        print(tfText.text)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
